export default {
  bind(el, binding) {
    el.$value = binding.value;
    el.handler = () => {
      const textarea = document.createElement('textarea');
      textarea.value = el.$value;
      document.body.appendChild(textarea);
      textarea.select();
      document.execCommand('copy');
      document.body.removeChild(textarea);
      alert('复制成功！');
    };
    el.addEventListener('click', el.handler);
  },
  componentUpdated(el, binding) {
    el.$value = binding.value;
  },
  unbind(el) {
    el.removeEventListener('click', el.handler);
  }
}